<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>文本导入</title>
    <title></title>
    <link rel="stylesheet" type="text/css" href="../js/easyui/themes/gray/easyui.css">
    <link rel="stylesheet" type="text/css" href="../js/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../js/easyui/demo/demo.css">
    <script type="text/javascript" src="../js/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="../js/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../js//esayui/locale/easyui-lang-zh_CN.js"></script>

    <script type="text/javascript">

        $(function () {
            load();
        });


        function load() {
            $("#txt").filebox({
                accept: '*.txt',
                buttonText: '选择文件',
                buttonAlign: 'right'
            });
        }


        function uploadTxt() {
            $("#uploadTxt").form({
                type : 'post',
                url : 'upload/txt',
                dataType : "json",
                onSubmit: function() {
                    var fileName= $('#txt').filebox('getValue');
                    //对文件格式进行校验
                    var d1=/\.[^\.]+$/.exec(fileName);
                    if (fileName == "") {
                        $.messager.alert('Excel批量用户导入', '请选择将要上传的文件!');
                        return false;
                    }else if(d1!=".txt"){
                        $.messager.alert('提示','请选择txt格式文件！','info');
                        return false;
                    }
                    $("#booten").linkbutton('disable');
                    return true;
                },
                success : function(result) {
                    var map=eval('('+result+')');
                    console.info(result);
                    console.info(map.msg);
                    if (map.msg==="上传成功") {
                        $.messager.alert('提示!', '上传成功','info',
                            function() {
                                $("#booten").linkbutton('enable');
                                window.close();
                            });
                    } else {
                        $.messager.confirm('提示',"上传失败!");
                        $("#booten").linkbutton('enable');
                    }
                }
            });
            $("#uploadTxt").form('submit');
        }
    </script>
</head>
<body>
<h2>文本上传</h2>
<div style="margin:20px 0;"></div>
<div>
    <table>
        <tr>
            <td>
    <form id="uploadTxt"  method="post" enctype="multipart/form-data">
    <input id="txt" name="txt" type="text" style="width:300px">
    </form>
            </td>
        </tr>
        <tr>
            <td>
            <a  id = "booten" onclick="uploadTxt()" class="easyui-linkbutton">上传</a>
            </td>
        </tr>
    </table>
</div>
</body>
</html>